package algorithm.poj.p1000;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLDecoder;
import java.util.StringTokenizer;

/**
 * 分析：
 * 平均每堆m个，每次只移动一个，那么最少需要(sigma |hi-m|)/2次
 * 
 * 
 * 实现：
 * 
 * 经验：
 * 
 * 教训：
 * 
 * @author wong.tong@gmail.com
 *
 */
public class P1477 {

	@SuppressWarnings("unchecked")
	public static void main(String[] args) throws Exception {

		InputStream input = null;
		if (false) {
			input = System.in;
		} else {
			URL url = P1477.class.getResource("P1477.txt");
			File file = new File(URLDecoder.decode(url.getPath(), "UTF-8"));
			input = new FileInputStream(file);
		}
		
		BufferedReader stdin = new BufferedReader(new InputStreamReader(input));

		String line = stdin.readLine();
		int count = 1;
		while (line != null && !"0".equals(line)) {
			int n = Integer.valueOf(line);

			int[] h = new int[n];
			line = stdin.readLine();
			StringTokenizer st = new StringTokenizer(line);
			int sum = 0;
			for (int i = 0; i < n; i ++) {
				h[i] = Integer.valueOf(st.nextToken());
				sum += h[i];
			}
			int m = sum/n;
			int moves = 0;
			for (int i = 0; i < n; i ++) {
				moves += Math.abs(h[i]-m);
			}
			moves /= 2;
			
			System.out.println("Set #" + count);
			System.out.println("The minimum number of moves is " + moves + ".\n");
			count ++;
			line = stdin.readLine();
		}
	}
}